import execjs
import json
import requests	
import base64
import urllib   #下载音乐的库
node = execjs.get(execjs.runtime_names.PhantomJS)

jsstr = ""
for item in ['jquery.min.js','aigei.js']:
    with open(item,"r") as f:
        jsstr+=f.read()

ctx = node.compile(jsstr)	#audio_mp3		2222154		   1534208400547  1ca62daebe
# data1 = ctx.call('dfu',"audio_mp3","31731353","1533988800890","f093181feb",'','','','')
data1 = ctx.call('dfu',"audio_mp3","2222154","1534208400547","1ca62daebe",'','','','')
data2 = ctx.call('cqbj',data1)
# data2 = json.loads(data2)
headers = json.loads(r'''{
    "Accept": "*/*",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Language": "zh-CN,zh;q=0.9",
    "Connection": "keep-alive",
    "Content-Length": "337",
    "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
    "Cookie": "gei_d_u=8578bef35b3f4bfaad4e117e4c2a6b85; oOO0OO0oOO00oo0o=true; geiweb-v=zZ+S93HA1QeA2Q6DYTRy5TQz0yEBzxT1Dyh6SZIjMWpyuUV5ZhD/qDUpyxv5xnOE; wueiornjk234kj=d8c2626028a64247bbc0a712cae2a200; JSESSIONID=42AC8A728961A0021C9A0AEAF7218CD3; OooOO000oOOO00o=7356761",
    "Host": "www.aigei.com",
    "Origin": "http://www.aigei.com",
    "Referer": "http://www.aigei.com/sound/class/?order=last&page=1",
    "User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36",
    "X-Requested-With": "XMLHttpRequest"
}''')
resp = requests.post("http://www.aigei.com/f/d/", data=data2, headers=headers)
message = json.loads(resp.text)['message']
urls = base64.b64decode(message)
urllib.request.urlretrieve(urls.decode('utf-8'),'title.mp3')